#include "test.h"
#include <QDebug>

Test::Test(QObject *parent) :
    QObject(parent),
    m_thread(new QThread),
    m_a(new A(1)),
    m_b(new A(2)),
    m_timer(new QTimer)
{
//    connect(m_timer, SIGNAL(timeout()),
//            m_thread, SLOT(start()));

//    connect(m_thread, SIGNAL(started()),
//            m_a, SLOT(do_start()), Qt::DirectConnection);

    qDebug() << __func__ << __LINE__ << " Pid: " << QThread::currentThreadId();

    connect(m_thread, SIGNAL(finished()),
            m_a, SLOT(do_finish()), Qt::DirectConnection);

    connect(m_timer, SIGNAL(timeout()),
            m_a, SLOT(do_start()));
    connect(m_timer, SIGNAL(timeout()),
            m_b, SLOT(do_start()));

    m_thread->start();

    m_a->moveToThread(m_thread);
    m_b->moveToThread(m_thread);

    m_timer->setInterval(1000);
    m_timer->start();

}

void Test::test()
{
   m_a->do_start();
}
